<?php

namespace Apps\AppApi\Method\BeautyParlor;

use Apps\AppApi\Method\BaseMethod;
use PhalconPlus\Api\Common\ResultStatus;
use Apps\Common\Models\CosPointBp;
use Apps\Common\Models\BeautyParlorTag;
use Apps\Common\Models\BeautyParlorTagInfo;


/**
 * 首页美容院推荐
 * @package Apps\AppApi\Method\BeautyParlor
 */
class Recommend extends BaseMethod
{
    /**
     * @var array
     */
    private $parlor = [];

    public function run()
    {
        $city_code = $this->getDataItem('citycode',0);
        $cityId = $this->getCityId($city_code);
        if($cityId <= 0) {
        	return $this->errorLog(ResultStatus::CITY_NOT_OPEN, '城市未开通');
        	//$cityId=2;
        }
        $list=CosPointBp::query()
        ->columns(['b.bp_name',
        	//'b.bp_cover',
        	'Apps\Common\Models\CosPointBp.img_url  as bp_cover',
        	'b.bp_address',
        	'b.bp_medal',
        	'b.bp_id',
        	])
        ->leftJoin('Apps\Common\Models\BeautyParlor','Apps\Common\Models\CosPointBp.bp_id=b.bp_id','b')
        ->where('Apps\Common\Models\CosPointBp.addr = "'.$cityId.'"')
        ->orderBy('Apps\Common\Models\CosPointBp.sort desc')
        ->execute()->toArray();
        foreach ($list as $k=>$v){
        	$list[$k]['medal_refund']=substr($list[$k]['bp_medal'],0,1);
        	$list[$k]['medal_verify']=substr($list[$k]['bp_medal'],1,1);
        	$list[$k]['bp_cover']="http://img.meelier.com/".$list[$k]['bp_cover'];
        	$list[$k]['tag']=BeautyParlorTag::query()
        	->columns('i.tag_title')
        	->leftJoin('Apps\Common\Models\BeautyParlorTagInfo','Apps\Common\Models\BeautyParlorTag.tag_id = i.tag_id','i')
        	->where("Apps\Common\Models\BeautyParlorTag.bp_id = ".$list[$k]['bp_id'])
        	->orderby("Apps\Common\Models\BeautyParlorTag.sort asc")
        	->limit(3,0)
        	->execute()->toArray();
        }
        foreach ($list as $k=>$v){
        	unset($list[$k]['bp_medal']);
        }
        if(count($list)==0){
        	unset($list);
        }
        $this->setResult($list);
    }

}